import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
//列表数据
export const columns: BasicColumn[] = [
  // {
  //  title: '有无投入品',
  //  align:"center",
  //  dataIndex: 'input_dictText'
  // },
  {
    title: '排产计划编号',
    align: "center",
    dataIndex: 'productScheduleId',
    customRender: (data) => {
      return data.record.productionSchedule.no;
    },
    helpMessage: '种植计划编号+2位自增流水号。例子：2023-1-1000-01-（计划编号）-01（自增流水号）'
  },
  {
    title: '种植作物',
    align: "center",
    slots: { customRender: 'products' },
    ellipsis: true,
  },
  {
    title: '农事操作',
    align: "center",
    dataIndex: 'productionOperation',
    customRender: (data) => {
      return data.record.productionSchedule.productionOperation_dictText;
    }
  },
  {
    title: '投入品',
    align: "center",
    dataIndex: 'inputUses',
    slots: { customRender: 'inputs' },
    // customRender: (data) => {
    //   return parseInt(data.record.input) ? data.record.inputUses.map(obj => obj.inputId_dictText).join(', ') : '无';
    // }
  },

  // {
  //  title: '投入品用法(kg/亩)',
  //  align:"center",
  //  dataIndex: 'actualUsage'
  // },
  {
    title: '计划用量',
    align: "center",
    dataIndex: 'actualUsage',
    // customRender: (data) => {
    //   return data.record.inputUses.map(obj => (obj.actualUsage || 0)+'kg').join(', ');
    // }
  },
  {
    title: '实际用量',
    align: "center",
    slots: { customRender: 'dosage' },
    // dataIndex: 'dosage',
    // customRender: (data) => {
    //   return data.record.inputUses.map(obj => obj.dosage+'kg').join(', ');
    // }
  },
  {
    title: '操作时间',
    align: "center",
    dataIndex: 'time',
    customRender: ({ text }) => {
      return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
    },
  },
  {
    title: '操作人',
    align: "center",
    dataIndex: 'operator'
  },
  // {
  //  title: '经度',
  //  align:"center",
  //  dataIndex: 'longitude'
  // },
  // {
  //  title: '纬度',
  //  align:"center",
  //  dataIndex: 'latitude'
  // },
  {
    title: '照片',
    align: "center",
    dataIndex: 'picturesList',
    width: 140,
    slots: { customRender: 'img' },
  },
  {
    title: '视频',
    align: "center",
    dataIndex: 'video',
    width: 140,
    slots: { customRender: 'video' }
  },
  {
    title: '是否上链',
    align: "center",
    dataIndex: 'cngData',
    customRender: (data) => {
      return data.record.cngData ? '已上链' : '未上链'
    },
  },
  {
    title: '位置',
    align: "center",
    dataIndex: 'location',
    customRender: (data) => {
      return data.record.longitude ? data.record.longitude + "\r\n" + data.record.latitude : ''
    },
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: "操作人",
    field: 'operator',
    component: 'Input'
  },
  {
    label: "有无投入品",
    field: 'input',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'yn',
      placeholder: '请选择有无投入品',
    },
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '有无投入品',
    field: 'input',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入有无投入品，字典数据，字典编码：yn!' },
      ];
    },
  },
  {
    label: '投入品用法(kg/亩)',
    field: 'actualUsage',
    component: 'InputNumber',
  },
  {
    label: '实际用量',
    field: 'dosage',
    component: 'InputNumber',
  },
  {
    label: '作业时间',
    field: 'time',
    component: 'DatePicker',
  },
  {
    label: '操作人',
    field: 'operator',
    component: 'Input',
  },
  {
    label: '经度',
    field: 'longitude',
    component: 'InputNumber',
  },
  {
    label: '纬度',
    field: 'latitude',
    component: 'InputNumber',
  },
  {
    label: '照片',
    field: 'pictures',
    component: 'Input',
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  },
];



/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
